package com.example.zhinongbao.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class CartDBHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "cart.db" ;
    private static final int DATABASE_VERSION = 1 ;
    public static final String TABLE_CART = "cart" ;
    public static final String CART_ID = "id" ;
    public static final String CART_GOODS_ID = "goodsId";
    public static final String CART_GOODS_NUM = "num";
    public static final String CART_USER = "user" ;
    public static final String CREATE_TABLE_CART = "CREATE TABLE " +
            TABLE_CART + " ( " +
            CART_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ," +
            CART_GOODS_ID + " INT , " +
            CART_GOODS_NUM + " INT , " +
            CART_USER + " TEXT )" ;

    public CartDBHelper(@Nullable Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_CART);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_CART);
        onCreate(db);
    }
}
